***********************************************************************************************
Replication Files for "Sovereign Risk and Economic Activity: The Role of Firm Entry and Exit"
Authors: Gaston Chaumont, Givi Melkadze, and Ia Vardishvili
Date: April 2025

Contact:
Ia Vardishvili (izv0013@auburn.edu)  
Givi Melkadze (gmelkadze@gsu.edu)  
Gaston Chaumont (gaston.chaumont@rochester.edu)  
***********************************************************************************************

Overview:
This replication package includes all files and instructions necessary to reproduce the results 
in the paper. All computations were performed on Windows. We used:
- Stata 18.0 for empirical analysis
- MATLAB R2024a for model simulation
- Intel Fortran Compiler (with Visual Studio integration) for model solution

-----------------------------------------------------------------------------------------------
(A) /ReplicationPackage/CODE (FORTRAN)
-----------------------------------------------------------------------------------------------
This folder contains the Fortran source code used to solve the model.

Key components:
- aa_MAIN_code.f90: Main control file. Initializes parameters, sets up the environment, and 
  calls all modules and subroutines needed for simulation.
- a_GridConstruction.f90: Grid setup for capital, productivity, and shocks.
- a_PotentialEntrantGrid.f90: Grid for the potential entrant signal distribution.
- a_ValueFunctionIteration.f90: Runs the value function iteration loop.
- a_ValueFunction.f90: Evaluates the value function.
- a_EntryDecision.f90: Computes optimal entry decisions.
- a_InvariantDistribution.f90: Computes firm distribution over states.
- a_ComputeStatistics.f90: Calculates model moments for validation and calibration.
- a_SaveParameters.f90: Saves results and parameter values.
- /Functions/: Auxiliary utilities (e.g., f_rouwenhorst, f_distributions, toolbox).

Output:
- Matlab_code/: Model simulation results (overall, high EFD).
- Matlab_code_Low_EFD/: Sector-specific outputs for low EFD.

How to Run:
1. Open Visual Studio with Intel Fortran integration.
2. Create a project and add all `FORTRAN` files from /CODE and /Functions.
3. Use `aa_MAIN_code.f90` as the main program.
4. Compile and run to generate outputs.

-----------------------------------------------------------------------------------------------
(B) /ReplicationPackage/MODEL
-----------------------------------------------------------------------------------------------
This folder contains all MATLAB scripts for loading Fortran outputs, simulating the calibrated 
model, and generating figures and tables from the paper and appendix.

Main workflow:
- A_RUN_ALL.m: Master script that reproduces all results, assuming `main_model.mat` exists.
  (If not, generate it using A_LOAD_DATA_FORTRAN.m)

Script Index:
- Figure5.m  
- Figure6.m 
- Figure7.m  
- Figure8.m 
- Figure9.m 
- Figure10.m  
- FigureB2.m
- FigureB3.m
- FigureC2.m
- Table3.m 
- Table4.m 
- Table5.m 
- Table6.m 
- TableC1.do – creates table C1.do

Notes:
- All outputs saved in ReplicationPackage/Results.
- Each script can run independently and includes the required preamble.
- MATLAB console prints statistics referenced in the text. .

Load Data:
Run A_LOAD_DATA_FORTRAN.m to build `main_model.mat`. This loads:
- Output_matlab: High-EFD data
- Output_matlab_LowEFD: Low-EFD data

Ensure file paths are correctly set before executing. This script calls:
- S1_LOAD_data_from_FORTRAN.m
- S2_LOAD_highEFD_from_FORTRAN.m
- S3_LOAD_lowEFD_from_FORTRAN.m
- S4_Invariant_distribution.m

Subfolders:
- Calibration (Data): Targets for calibration (Section 4)
- EventStudy: Sovereign risk simulations (Section 5)
- LoadDataFortran: Code to load Fortran output
- ModelEconomy: Steady-state statistics and simulation routines

-----------------------------------------------------------------------------------------------
(C) /ReplicationPackage/EMPIRICS
-----------------------------------------------------------------------------------------------
This folder contains all Stata `.do` files for the empirical analysis.

Core Tables (already cleaned data):
1. Table1_TableB1_TableB2_TableB3.do  
   - Table 1 and Appendix Tables B.1–B.3  

2. Table2_TableB4_TableB5_TableB6.do  
   - Table 2 and Appendix Tables B.4–B.6  

3. SumStat_TableA1_TableA2_TableA3_TableA4.do  
   - Summary statistics: Tables A.1–A.4

Raw Data Preparation:
To rebuild the dataset from scratch:
 Go to: Eurostat Employer Business Demography Data Processing                                     
                                                                                           
 Source: Eurostat Business Demography - Historical Data (2004–2020)                        
 Dataset: Employer business demography by size class and NACE Rev. 2 activity (bd_9fh)     
                                                                                           
 Website: https://ec.europa.eu/eurostat/web/business-demography/database                   
 Dataset Viewer: https://ec.europa.eu/eurostat/databrowser/view/bd_9fh_sz_cl_r2/default/table?lang=en&category=bsd.bd.bd_h *
                                                                                           
 Instructions:                                                                              
 a. Download the full dataset:                                                             
    - File format: SDMX-CSV 2.0 (.csv)                                                     
    - Data scope: Full dataset                                                             
    - Check: Compress file (.gzip)                                                        
    - Click: Download                                                                      
                                                                                           
 OR use the API to download the same data directly:                                        
 https://ec.europa.eu/eurostat/api/dissemination/sdmx/3.0/data/dataflow/ESTAT/bd_9fh_sz_cl_r2/1.0?compress=true&format=csvdata&formatVersion=2.0&lang=en&labels=name *
                                                                                           
                                                                                                                                                                               
 b. Save the downloaded .csv file (recommended name: estat_bd_9fh_sz_cl_r2_en.csv)         
    in the directory: /Data/Original                                                       
                                                                                           
 c. Run this script /ReplicationPackage/EMPIRICS/IMPORT_DATA.do  

 

-----------------------------------------------------------------------------------------------
(D) /ReplicationPackage/DATA
-----------------------------------------------------------------------------------------------
- Contains all cleaned datasets used for empirical analysis.
- Raw files should be stored in `/Data/Original`.
- Use EMPIRICS scripts to clean and construct analysis-ready data.

-----------------------------------------------------------------------------------------------
(E) /ReplicationPackage/RESULTS
-----------------------------------------------------------------------------------------------
- Stores all tables (in `.tex` format) and figures generated by both the MODEL and EMPIRICS 
  folders.
